<?php
	require("../config.php");
	require("lib.image.php");
	function mkdir_recursive($pathname, $mode)
	{
	    is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode);
	    return is_dir($pathname) || @mkdir($pathname, $mode);
	}
	$ftmp = $_FILES['image']['tmp_name'];
	$oname = $_FILES['image']['name'];
	$nname = images::ext1($oname);
	$ext = images::ext2($oname);
	$accents1 = array(" ","'",'"',"-","à","á","â","ã","ä","å","ò","ó","ô","õ","ö","ø","è","é","ê","ë","ç","ì","í","î","ï","ù","ú","û","ü","ÿ","ñ");
	$accents2 = array("_","_","_","_","a","a","a","a","a","a","o","o","o","o","o","o","e","e","e","e","c","i","i","i","i","u","u","u","u","y","n");
	$nname = str_replace($accents1,$accents2, $nname);
	$dir = '../img/'.date('Y/m').'/';
	mkdir_recursive($dir, 0700);
	$fname = $dir.$nname.$ext;
	if(move_uploaded_file($ftmp, $fname))
	{
		$tiny = $dir.'__'.$nname.images::ext2($oname);
		$display = $dir.'_'.$nname.images::ext2($oname);
		$img_type = images::type($fname);
		images::cropImg($fname,$tiny,$img_type,$tiny_width,$tiny_height,'error.jpg');
		if(isset($_POST['redim']))
			images::cropImg($fname,$display,$img_type,$display_width,$display_height,'error.jpg');
		echo '<script language="javascript" type="text/javascript">';
		echo "window.top.window.stopUploadOK('OK')";
		echo "</script>\n";
	}
	else
	{
	?>
		<script language="javascript" type="text/javascript">
			window.top.window.stopUploadError('Erreur');
		</script> 
	<?php
	}
?>